#include "mainwindow.h"
#include "ui_mainwindow.h"

QStringList hnCityList = {"驻马店市","漯河市","郑州市","洛阳市"};
QStringList gdCityList = {"广州市","深圳市","珠海市","东莞市"};
QStringList zjCityList = {"杭州市","宁波市","嘉兴市","绍兴市"};
QStringList hbCityList = {"石家庄市","保定市","廊坊市","衡水市"};
QStringList nmgCityList = {"呼和浩特市","包头市","呼伦贝尔市","赤峰市"};


MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // 添加省份
    ui->cbProvince->addItem(QIcon(":/icon/apple.png"),"河南省");
    ui->cbProvince->addItem(QIcon(":/icon/banana.png"),"广东省");
    ui->cbProvince->addItem(QIcon(":/icon/orange.png"),"浙江省");
    ui->cbProvince->addItem(QIcon(":/icon/pear.png"),"河北省");
    ui->cbProvince->addItem(QIcon(":/icon/watermelon.png"),"内蒙古自治区");

    // 添加城市
    ui->cbCity->addItems(hnCityList);


    connect(ui->cbProvince, SIGNAL(currentIndexChanged(int)), this, SLOT(onProvinceCurrentIndexChanged(int)));
    connect(ui->cbSchool, SIGNAL(currentIndexChanged(int)), this, SLOT(onSchoolChanged(int)));
    connect(ui->cbCity, SIGNAL(currentIndexChanged(int)), this, SLOT(onCityChanged(int)));

    QString name = ui->leName->text();
    QString school = ui->cbSchool->currentText();
    QString province = ui->cbProvince->currentText();
    QString city = ui->cbCity->currentText();

    ui->leResult->setText("姓名: " + name + "来自于：" + school + province + city);
}

MainWindow::~MainWindow()
{
    delete ui;
}

/** 省份改变
 * @brief MainWindow::onProvinceCurrentIndexChanged
 * @param index
 */
void MainWindow::onProvinceCurrentIndexChanged(int index)
{
    // 清空城市
    ui->cbCity->clear();

    switch(index){
        case 0:
            ui->cbCity->addItems(hnCityList);
            break;
        case 1:
            ui->cbCity->addItems(gdCityList);
            break;
        case 2:
            ui->cbCity->addItems(zjCityList);
            break;
        case 3:
            ui->cbCity->addItems(hbCityList);
            break;
        case 4:
            ui->cbCity->addItems(nmgCityList);
            break;
    }

    QString name = ui->leName->text();
    QString school = ui->cbSchool->currentText();
    QString province = ui->cbProvince->currentText();
    QString city = ui->cbCity->currentText();

    ui->leResult->setText("姓名: " + name + "来自于：" + school + province + city);

}

/** 学校变化
 * @brief MainWindow::onSchoolChanged
 * @param index
 */
void MainWindow::onSchoolChanged(int index)
{
    QString name = ui->leName->text();
    QString school = ui->cbSchool->currentText();
    QString province = ui->cbProvince->currentText();
    QString city = ui->cbCity->currentText();

    ui->leResult->setText("姓名: " + name + "来自于：" + school + province + city);
}

/** 城市变化
 * @brief MainWindow::onCityChanged
 * @param index
 */
void MainWindow::onCityChanged(int index)
{
    QString name = ui->leName->text();
    QString school = ui->cbSchool->currentText();
    QString province = ui->cbProvince->currentText();
    QString city = ui->cbCity->currentText();

    ui->leResult->setText("姓名: " + name + "来自于：" + school + province + city);
}
